package com.yaolaizaixian.merchant.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yaolaizaixian.merchant.R;
import com.yaolaizaixian.merchant.bean.SalesWeekList;

import java.util.List;

/**
 * Created by ylzx on 2017/2/27.
 */
public class FragmentSalesWeekAdapter extends RecyclerView.Adapter<FragmentSalesWeekAdapter.ViewHolder> {


    private  String stroeName;
    public List<SalesWeekList> datas;
    private Context mcontext;

    private OnItemClickListener mOnItemClickListener;

    public FragmentSalesWeekAdapter(Context context, List<SalesWeekList> datas,String shopname) {

        this.datas = datas;
        this.mcontext = context;
        this.stroeName=shopname;

    }

    //创建新View，被LayoutManager所调用
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {

        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_salesweek, viewGroup, false);
        return new ViewHolder(view);
    }

    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, final int position) {

        SalesWeekList salesWeekData = datas.get(position);
        //标题
        viewHolder.tvSalesweekShopname.setText(stroeName);
        viewHolder.tvSalesweekTime.setText(salesWeekData.getLife_so_master_id());
        viewHolder.tvSalesweekNumber.setText(salesWeekData.getInput_time());
        viewHolder.tvSalesweekMoney.setText("￥"+salesWeekData.getTotal_amt());
        viewHolder.tvSalesweekRemarks.setText(salesWeekData.getRemark());
//        餐饮=10 电影=20 机票=30 线上收款=40
        if ("10".equals(salesWeekData.getType())){
            viewHolder.tvSalesweekType.setText("餐饮");
        }else if ("20".equals(salesWeekData.getType())){
            viewHolder.tvSalesweekType.setText("电影");
        }else if ("30".equals(salesWeekData.getType())){
            viewHolder.tvSalesweekType.setText("机票");
        }else {
            viewHolder.tvSalesweekType.setText("线上收款");
        }
        //订单类型 5：待支付 10：已支付 15：出票成功 100：交易成功 -100：交易关闭
        if ("5".equals(salesWeekData.getStatus())){
        viewHolder.tvSalesweekState.setText("待支付");
        }else if ("10".equals(salesWeekData.getStatus())){
            viewHolder.tvSalesweekState.setText("已支付");
        }else if ("15".equals(salesWeekData.getStatus())){
            viewHolder.tvSalesweekState.setText("出票成功");
        }else if ("100".equals(salesWeekData.getStatus())){
            viewHolder.tvSalesweekState.setText("交易成功");
        }else if ("-100".equals(salesWeekData.getStatus())){
            viewHolder.tvSalesweekState.setText("交易关闭");
        }

        if (mOnItemClickListener != null) {
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {

                    mOnItemClickListener.onClick(position);
                }
            });

            viewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {

                    mOnItemClickListener.onLongClick(position);
                    return false;
                }
            });
        }
    }

    //获取数据的数量
    @Override
    public int getItemCount() {

        return datas.size();
    }

    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public static class ViewHolder extends RecyclerView.ViewHolder {

        TextView tvSalesweekShopname;
        TextView tvSalesweekTime;
        TextView tvSalesweekNumber;
        TextView tvSalesweekType;
        TextView tvSalesweekState;
        TextView tvSalesweekRemarks;
        TextView tvJine;
        TextView tvSalesweekMoney;

        public ViewHolder(View view) {
            super(view);

            tvSalesweekShopname = (TextView) view.findViewById(R.id.tv_salesweek_shopname);
            tvSalesweekTime = (TextView) view.findViewById(R.id.tv_salesweek_time);
            tvSalesweekNumber = (TextView) view.findViewById(R.id.tv_salesweek_number);
            tvSalesweekType = (TextView) view.findViewById(R.id.tv_salesweek_type);
            tvSalesweekState = (TextView) view.findViewById(R.id.tv_week_state);
            tvSalesweekRemarks = (TextView) view.findViewById(R.id.tv_salesweek_remarks);
            tvJine = (TextView) view.findViewById(R.id.tv_jine);
            tvSalesweekMoney = (TextView) view.findViewById(R.id.tv_salesweek_money);

        }
    }


    public interface OnItemClickListener {
        void onClick(int position);

        void onLongClick(int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }


}
